import type { ObjectDirective } from 'vue'
import dayjs from 'dayjs'

export const formatTime: ObjectDirective = {
  mounted(el: HTMLButtonElement, binding, vnode) {
    const value = binding.value || 'YYYY-MM-DD HH:mm:ss'
    const textContent: any = el.textContent
    // console.log(typeof(textContent), '类型')
    let timestamp = parseInt(textContent)
    if (textContent?.length === 10) {
      timestamp = timestamp * 1000
    }
    // console.log(dayjs(timestamp).format(value))
    el.textContent =  dayjs(timestamp).format(value)
  }
}
